package cn.zhaoyuening.crm.service.impl;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FileUtils;

import cn.zhaoyuening.crm.dao.ClassDao;
import cn.zhaoyuening.crm.domain.CrmClass;
import cn.zhaoyuening.crm.service.ClassService;

public class ClassServiceImpl implements ClassService{
	private ClassDao classDao;
	
	@Override
	public List<CrmClass> findAll() {
		List<CrmClass> list = classDao.findAll();
		return list;
	}
	
	
	public ClassDao getClassDao() {
		return classDao;
	}
	public void setClassDao(ClassDao classDao) {
		this.classDao = classDao;
	}


	@Override
	public CrmClass findById(String id) {
		CrmClass clazz = this.classDao.findById(id);
		return clazz;
	}


	@Override
	public void uploadClassTable(File classTable, CrmClass clazz) {
		//copy file
		File copyPath = new File(clazz.getUploadPath());
		try {
			FileUtils.copyFile(classTable, copyPath);
		} catch (IOException e) {
			e.printStackTrace();
		}
		//update class classTable data
		CrmClass findClass = this.classDao.findById(clazz.getClassId());
		findClass.setUploadFilename(clazz.getUploadFilename());
		findClass.setUploadPath(clazz.getUploadPath());
		findClass.setUploadTime(clazz.getUploadTime());
		
		this.classDao.addOrEdit(findClass);
	}


	@Override
	public CrmClass findById(CrmClass clazz) {
		return classDao.findById(clazz.getClassId());
	}
	
	

}
